Skip to content

fix: add request timeouts to multimodal URL fetches - #2507

Closed
bunlongheng wants to merge 1 commit into
567-labs:mainfrom
bunlongheng:fix/security-request-timeouts
Closed

fix: add request timeouts to multimodal URL fetches#2507
bunlongheng wants to merge 1 commit into
567-labs:mainfrom
bunlongheng:fix/security-request-timeouts

Conversation

@bunlongheng

Copy link
Copy Markdown
Contributor

Problem

Several requests.get / requests.head calls in the multimodal helpers download image, audio, and PDF content from remote URLs without passing a timeout. Because Python's requests has no default timeout, a slow or unresponsive host can hang the calling thread indefinitely (uncontrolled resource consumption, CWE-400). This is a denial-of-service hardening gap: a single unreachable media URL can stall a request pipeline forever.

The GCS helpers in the same module (from_gs_url) already use a 30s timeout, and bedrock/handlers.py uses timeout=30 too, so the codebase already treats 30s as the convention. This PR simply extends that same default to the remaining fetches.

Fixed call sites

  • instructor/v2/core/multimodal.py - Image.from_url (HEAD probe), Image.url_to_base64, Audio.from_url, PDF.from_url (HEAD probe)
  • instructor/v2/providers/anthropic/multimodal.py - pdf_to_anthropic
  • instructor/v2/providers/genai/multimodal.py - image_to_genai, pdf_to_genai
  • instructor/v2/providers/openai/multimodal.py - pdf_to_openai

Change

Each remote fetch now passes timeout=30, matching the existing convention. No behavior change for healthy hosts; unresponsive hosts now fail fast instead of hanging.

Tests

Added two regression tests in tests/multimodal/test_multimodal.py asserting a timeout is passed on both the requests.get and requests.head paths. Full multimodal suite passes: 62 passed, 1 skipped.

Several requests.get/head calls that download image, audio, and PDF
content from remote URLs did not pass a timeout, so a slow or
unresponsive host could hang the calling thread indefinitely
(uncontrolled resource consumption, CWE-400). The GCS helpers in the
same module already use a 30s timeout; this applies the same default
to the remaining fetches and adds regression tests asserting a timeout
is passed.
@jxnl

jxnl commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Consolidated and merged in #2510. The original timeout changes and authorship were preserved; the consolidation also repaired four stale request mocks, asserted all changed timeout paths, and passed the full CI/release matrix.

@jxnl jxnl closed this Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants